package org.social.db.bean;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.social.db.cache.ActivityCache;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.build.data.base.BasePojo;
import static org.social.db.StaticResource.ActivityResource.*;
import java.util.List;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import org.social.db.cache.ActivityEntryCache;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.social.db.StaticResource.ActivityResource.*;
/**
 * 活动
 */
public class Activity extends BasePojo<Activity> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[1];
	
	/**
	* id
	*/
	private int id;
	
	/**
	* 状态
	*/
	private int status;
	
	/**
	* 是否激活
	*/
	private boolean active;
	
	/**
	* 开始时间
	*/
	private java.util.Date startDate;
	
	/**
	* 结束时间
	*/
	private java.util.Date endDate;
	
	/**
	* 最后重置时间
	*/
	private java.util.Date resetDate;
	
	/**
	* 活动类型
	*/
	private int type;
	
	/**
	* 重置类型
	*/
	private int resetType;
	
	/**
	* 数据类型
	*/
	private int dataType;
	
	/**
	* 备注
	*/
	private Map remark;
	
	/**
	* 顺序
	*/
	private int rank;
	
	/**
	* 期数(版本号)
	*/
	private int ver;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	
	@Deprecated
	public static Activity builder() {
		Activity activity = new Activity();
		return activity;
	}
	
	@Deprecated
	public Activity() {
		super();
	}
	
	public Activity(int id, int status, boolean active, java.util.Date startDate, java.util.Date endDate, java.util.Date resetDate, int type, int resetType, int dataType, Map remark, int rank, int ver) {
		super();
		this.id = id;
		this.status = status;
		this.active = active;
		this.startDate = startDate;
		this.endDate = endDate;
		this.resetDate = resetDate;
		this.type = type;
		this.resetType = resetType;
		this.dataType = dataType;
		this.remark = remark;
		this.rank = rank;
		this.ver = ver;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
	}
	
	/**
	 * id
	 */
	public int getId() {return id;}
	
	/**
	 * id
	 */
	public Activity setId(int id) {this.id = id;return this;}
	
	/**
	 * 状态
	 */
	public int getStatus() {return status;}
	
	/**
	 * 状态
	 */
	public Activity setStatus(int status) {this.status = status;return this;}
	
	/**
	 * 是否激活
	 */
	public boolean isActive() {return active;}
	
	/**
	 * 是否激活
	 */
	public Activity setActive(boolean active) {this.active = active;return this;}
	
	/**
	 * 开始时间
	 */
	public java.util.Date getStartDate() {return startDate;}
	
	/**
	 * 开始时间
	 */
	public Activity setStartDate(java.util.Date startDate) {this.startDate = startDate;return this;}
	
	/**
	 * 结束时间
	 */
	public java.util.Date getEndDate() {return endDate;}
	
	/**
	 * 结束时间
	 */
	public Activity setEndDate(java.util.Date endDate) {this.endDate = endDate;return this;}
	
	/**
	 * 最后重置时间
	 */
	public java.util.Date getResetDate() {return resetDate;}
	
	/**
	 * 最后重置时间
	 */
	public Activity setResetDate(java.util.Date resetDate) {this.resetDate = resetDate;return this;}
	
	/**
	 * 活动类型
	 */
	public int getType() {return type;}
	
	/**
	 * 活动类型
	 */
	public Activity setType(int type) {this.type = type;return this;}
	
	/**
	 * 重置类型
	 */
	public int getResetType() {return resetType;}
	
	/**
	 * 重置类型
	 */
	public Activity setResetType(int resetType) {this.resetType = resetType;return this;}
	
	/**
	 * 数据类型
	 */
	public int getDataType() {return dataType;}
	
	/**
	 * 数据类型
	 */
	public Activity setDataType(int dataType) {this.dataType = dataType;return this;}
	
	/**
	 * 备注
	 */
	public Map getRemark() {return remark;}
	
	/**
	 * 备注
	 */
	public Activity setRemark(Map remark) {this.remark = remark;return this;}
	
	/**
	 * 备注
	 */
	public String getRemarkString() {
	    return toJSONString(remark);
	}
	
	/**
	 * 备注
	 */
	public Map initRemarkString(String str) {
		return forJsonObject(str,Map.class);
	}	
	/**
	 * 顺序
	 */
	public int getRank() {return rank;}
	
	/**
	 * 顺序
	 */
	public Activity setRank(int rank) {this.rank = rank;return this;}
	
	/**
	 * 期数(版本号)
	 */
	public int getVer() {return ver;}
	
	/**
	 * 期数(版本号)
	 */
	public Activity setVer(int ver) {this.ver = ver;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected Activity setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected Activity setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.status;
        values[2] = this.active;
        values[3] = this.startDate;
        values[4] = this.endDate;
        values[5] = this.resetDate;
        values[6] = this.type;
        values[7] = this.resetType;
        values[8] = this.dataType;
        values[9] = this.remark;
        values[10] = this.rank;
        values[11] = this.ver;
        values[12] = this.createDate;
        values[13] = this.modifiedDate;
        return values;
	}
	
	public Activity deepCopy(){
		Activity activity = null;
		try {
			activity = (Activity) super.clone();
		    activity.setStartDate(ToolCopy.copyObject(this.startDate));
		    activity.setEndDate(ToolCopy.copyObject(this.endDate));
		    activity.setResetDate(ToolCopy.copyObject(this.resetDate));
		    activity.setRemark(ToolCopy.copyObject(this.remark));
		    activity.setCreateDate(ToolCopy.copyObject(this.createDate));
		    activity.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    activity.indexValues = ArrayUtils.clone(indexValues);
			return activity;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return activity;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.status);
        map.put(keys[2], this.active);
        map.put(keys[3], this.startDate);
        map.put(keys[4], this.endDate);
        map.put(keys[5], this.resetDate);
        map.put(keys[6], this.type);
        map.put(keys[7], this.resetType);
        map.put(keys[8], this.dataType);
        map.put(keys[9], this.remark);
        map.put(keys[10], this.rank);
        map.put(keys[11], this.ver);
        map.put(keys[12], this.createDate);
        map.put(keys[13], this.modifiedDate);
        return map;
    }
    
    protected Activity createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.status = (int)map.get(keys[1]);
   		this.active = (boolean)map.get(keys[2]);
   		this.startDate = (java.util.Date)map.get(keys[3]);
   		this.endDate = (java.util.Date)map.get(keys[4]);
   		this.resetDate = (java.util.Date)map.get(keys[5]);
   		this.type = (int)map.get(keys[6]);
   		this.resetType = (int)map.get(keys[7]);
   		this.dataType = (int)map.get(keys[8]);
   		this.remark = (Map)map.get(keys[9]);
   		this.rank = (int)map.get(keys[10]);
   		this.ver = (int)map.get(keys[11]);
   		this.createDate = (java.util.Date)map.get(keys[12]);
   		this.modifiedDate = (java.util.Date)map.get(keys[13]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.status);
        obj.put(keys[2], this.active);
        obj.put(keys[3], this.startDate);
        obj.put(keys[4], this.endDate);
        obj.put(keys[5], this.resetDate);
        obj.put(keys[6], this.type);
        obj.put(keys[7], this.resetType);
        obj.put(keys[8], this.dataType);
        obj.put(keys[9], this.remark);
        obj.put(keys[10], this.rank);
        obj.put(keys[11], this.ver);
        obj.put(keys[12], this.createDate);
        obj.put(keys[13], this.modifiedDate);
        return obj;
    }
    
    protected Activity createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.status = obj.getIntValue(keys[1]);
	    this.active = obj.getBooleanValue(keys[2]);
	    this.startDate = obj.getDate(keys[3]);
	    this.endDate = obj.getDate(keys[4]);
	    this.resetDate = obj.getDate(keys[5]);
	    this.type = obj.getIntValue(keys[6]);
	    this.resetType = obj.getIntValue(keys[7]);
	    this.dataType = obj.getIntValue(keys[8]);
		this.remark = obj.getObject(keys[9],Map.class);
	    this.rank = obj.getIntValue(keys[10]);
	    this.ver = obj.getIntValue(keys[11]);
	    this.createDate = obj.getDate(keys[12]);
	    this.modifiedDate = obj.getDate(keys[13]);
        return this;
    }
    
    
    public Activity createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getInt(SOURCE_COLUMN_NAMES[0]);
	    this.status = rs.getInt(SOURCE_COLUMN_NAMES[1]);
	    this.active = rs.getBoolean(SOURCE_COLUMN_NAMES[2]);
	    this.startDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[3]);
	    this.endDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[4]);
	    this.resetDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[5]);
	    this.type = rs.getInt(SOURCE_COLUMN_NAMES[6]);
	    this.resetType = rs.getInt(SOURCE_COLUMN_NAMES[7]);
	    this.dataType = rs.getInt(SOURCE_COLUMN_NAMES[8]);
		this.remark = forJsonObject(rs.getString(SOURCE_COLUMN_NAMES[9]),Map.class);
	    this.rank = rs.getInt(SOURCE_COLUMN_NAMES[10]);
	    this.ver = rs.getInt(SOURCE_COLUMN_NAMES[11]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[12]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[13]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.status);
	    byteBuf.writeBoolean(this.active);
	    byteBuf.writeDate(this.startDate);
	    byteBuf.writeDate(this.endDate);
	    byteBuf.writeDate(this.resetDate);
	    byteBuf.writeInt(this.type);
	    byteBuf.writeInt(this.resetType);
	    byteBuf.writeInt(this.dataType);
	    byteBuf.writeObject(this.remark);
	    byteBuf.writeInt(this.rank);
	    byteBuf.writeInt(this.ver);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
    }
	
	protected Activity readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.status = byteBuf.readInt(null);
	    this.active = byteBuf.readBoolean(null);
	    this.startDate = byteBuf.readDate(null);
	    this.endDate = byteBuf.readDate(null);
	    this.resetDate = byteBuf.readDate(null);
	    this.type = byteBuf.readInt(null);
	    this.resetType = byteBuf.readInt(null);
	    this.dataType = byteBuf.readInt(null);
	    this.remark = (Map)byteBuf.readObject();
	    this.rank = byteBuf.readInt(null);
	    this.ver = byteBuf.readInt(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		// activity_entry
		map.put(keys[0],exprotHelp(this.getActivityEntrysFkActivityId(),e));
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		// activity_entry
		improtHelp(map.getJSONArray(keys[0]),ActivityEntry.builder(),e,0,this.getId());
		return true;
    }
    
	/** 取得[activity_entry] */
	public List<ActivityEntry> getActivityEntrysFkActivityId(){
		return ActivityEntryCache.me().getByActivityId(id);
	}
	
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public Activity insert(){
    	return ActivityCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public Activity update(){
    	return ActivityCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return ActivityCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public Activity insertAndFlush(){
    	return ActivityCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Activity updateAndFlush(){
    	return ActivityCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return ActivityCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public Activity syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((int)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}